/**
 * Created by Administrator on 2017/7/25.
 */
angular.module('module.activity_audit',[])
    .config(['$stateProvider',function ($stateProvider) {
        $stateProvider
            .state('home.activity_audit',{
                url:'/activity_audit',
                params:{activityId:null},
                templateUrl:'view/activity_audit.html',
                controller:'activity_audit_controller'
            })
    }])
    .controller('activity_audit_controller',['$scope',"$stateParams","ActivityService",'OriginatorService',function ($scope,$stateParams,ActivityService,OriginatorService) {
        console.log("activity_audit_controller启动成功");
        console.log("$stateParams",$stateParams);

        function getActivity(query_terms,sfun,efun) {
            ActivityService.getActivity(query_terms,function (data) {
                console.log(data);
                $scope.activity=data;
                $scope.activity.activeTimeString=new Date($scope.activity.activeTime).toLocaleString();
                if(sfun){
                    sfun()
                }
            },efun)
        }

        function getOriginator(query_terms,sfun,efun) {
            OriginatorService.getOriginator(query_terms,function (data) {
                console.log(data);
                $scope.originator=data;
                if(sfun){
                    sfun()
                }
            },efun);
        }

        $scope.updateActivity=function(state){
            $scope.activity.activeState=state;
            ActivityService.updateActivity($scope.activity,function (data) {
                console.log("成功",data)
            },function (data) {
                console.log('失败',data)
            })
        };

        getActivity({activeId:$stateParams.activityId},function () {
            getOriginator({originatorId:$scope.activity.originatorId})
        });

    }]);